<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * TomatoCart Open Source Shopping Cart Solution
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License v3 (2007)
 * as published by the Free Software Foundation.
 *
 * @package      TomatoCart
 * @author       TomatoCart Dev Team
 * @copyright    Copyright (c) 2009 - 2012, TomatoCart. All rights reserved.
 * @license      http://www.gnu.org/licenses/gpl.html
 * @link         http://tomatocart.com
 * @since        Version 2.0
 * @filesource
*/

// ------------------------------------------------------------------------

/**
 * Articles Model
 *
 * @package		TomatoCart
 * @subpackage	tomatocart
 * @category	template-module-controller
 * @author		TomatoCart Dev Team
 * @link		http://tomatocart.com/wiki/
 */
class Articles_Model extends CI_Model
{
    /**
     * Articles Model Constructor
     *
     * @access public
     * @param string
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Get Article Category Name
     *
     * @access public
     * @param $articles_categories_id articles categories id
     * @return string
     */
    public function get_articles_category_name($articles_categories_id) 
    {
        $result = $this->db->select('articles_categories_name')
            ->from('articles_categories_description')
            ->where('articles_categories_id', $articles_categories_id)
            ->where('language_id', lang_id())
            ->get();

        if ($result->num_rows() > 0)
        {
            $row = $result->row_array();
            
            return $row['articles_categories_name'];
        }
        
        return NULL;
    }
    
    /**
     * Get Articles
     *
     * @access public
     * @param int $articles_categories_id articles categories id
     * @param int $count number of articles to be displayed
     * @return array new products array
     */
    public function get_articles($articles_categories_id, $count) 
    {
        $result = $this->db->select('a.articles_id, ad.articles_name, ad.articles_url')
            ->from('articles a')
            ->join('articles_description ad', 'a.articles_id = ad.articles_id', 'inner')
            ->where('a.articles_status', 1)
            ->where('a.articles_categories_id', $articles_categories_id)
            ->where('ad.language_id', lang_id())
            ->order_by('articles_order', 'desc')
            ->limit($count)
            ->get();

        if ($result->num_rows() > 0)
        {
            return $result->result_array();
        }
        
        return NULL;
    }
}

/* End of file mod.articles.php */
/* Location: ./system/tomatocart/modules/articles/mod.articles.php */